using UnityEngine;

public class PlayerAIState_Offense_Dribble : State<PlayerAI>
{
	public static PlayerAIState_Offense_Dribble instance;

	private PlayerAIState_Offense_Dribble()
	{
	}

	public static PlayerAIState_Offense_Dribble getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerAIState_Offense_Dribble();
		}
		return instance;
	}

	public override void enter(PlayerAI owner)
	{
		base.enter(owner);
		owner.player.do_dribble_run();
		owner.offense_dribble_is_shoot_without_defense = false;
		owner.offense_dribble_is_shoot_on_defense = false;
		owner.offense_dribble_is_ok_layup_or_dunk = false;
		owner.offense_dribble_time_ok_layup_or_dunk_keepmove = -1f;
		if (!owner.player.IsCrossHalfCourt() && GameData.IsFinishTutorial)
		{
			owner.time_Stop = Random.Range(0f, 0.8f);
		}
	}

	public override void fixedUpdate(PlayerAI owner)
	{
		base.fixedUpdate(owner);
		if (owner.time_Stop > 0f)
		{
			owner.time_Stop -= Time.fixedDeltaTime;
			owner.player.do_dribble_stay();
			return;
		}
		owner.player.do_dribble_run();
		if (owner.player.team.is_shoot_at_offense_time_end && owner.player.team.time_offense < 1f)
		{
			owner.do_offense_shoot();
		}
		else if (!DSS.IsSomeOneFront(owner.player.myTransform, owner.player.getParaTeam().getPlayer_ClosestToTarget(owner.player.getPosition()).getPosition()))
		{
			owner.offense_dribble_is_shoot_on_defense = false;
			if (DSS.IsCanDunk(owner.player) || DSS.IsCanLayUp(owner.player))
			{
				if (!owner.offense_dribble_is_ok_layup_or_dunk)
				{
					owner.offense_dribble_is_ok_layup_or_dunk = true;
					if (MathHelper.isInPercent(owner.player.team.percent_layupdunk_trigger_shoot))
					{
						owner.do_offense_shoot();
					}
					else
					{
						owner.offense_dribble_time_ok_layup_or_dunk_keepmove = owner.player.team.time_layupdunk_wait_trigger;
					}
					return;
				}
				owner.offense_dribble_time_ok_layup_or_dunk_keepmove -= Time.fixedDeltaTime;
				if (owner.offense_dribble_time_ok_layup_or_dunk_keepmove < 0f)
				{
					owner.do_offense_shoot();
				}
				if (MathHelper.getSqrDistance(owner.player.getPosition(), owner.player.getOffenseBasketPos()) < 2f)
				{
					if (MathHelper.isInPercent(owner.player.team.percent_shoot_under_basketry))
					{
						owner.do_offense_shoot();
					}
					else
					{
						owner.do_offense_pass();
					}
				}
				else
				{
					GameHelper.MoveTo(owner.player, owner.player.getOffenseBasketPos(), owner.player.getMoveSpeed(), isLookAtTargetPos: true);
				}
				return;
			}
			if (!owner.offense_dribble_is_shoot_without_defense && DSS.IsCanShoot(owner.player) && !owner.player.isSingleCrossOver)
			{
				owner.offense_dribble_is_shoot_without_defense = true;
				if (MathHelper.isInPercent(owner.player.team.percent_shoot_without_defense))
				{
					owner.do_offense_shoot();
					return;
				}
				if (MathHelper.isInPercent(owner.player.team.percent_pass_without_defense))
				{
					owner.do_offense_pass();
					return;
				}
			}
			if (MathHelper.getSqrDistance(owner.player.getPosition(), owner.player.getOffenseBasketPos()) < 2f)
			{
				if (MathHelper.isInPercent(owner.player.team.percent_shoot_under_basketry))
				{
					owner.do_offense_shoot();
				}
				else
				{
					owner.do_offense_pass();
				}
			}
			else
			{
				GameHelper.MoveTo(owner.player, owner.player.getOffenseBasketPos(), owner.player.getMoveSpeed(), isLookAtTargetPos: true);
			}
		}
		else if (!owner.player.isSingleCrossOver)
		{
			owner.offense_dribble_is_shoot_without_defense = false;
			if (!owner.offense_dribble_is_shoot_on_defense && DSS.IsCanShoot(owner.player))
			{
				owner.offense_dribble_is_shoot_on_defense = true;
				if (MathHelper.isInPercent(owner.player.team.percent_shoot_on_defense))
				{
					owner.do_offense_shoot();
					return;
				}
			}
			if (MathHelper.isInPercent(owner.player.team.percent_pass_on_defense))
			{
				owner.do_offense_pass();
			}
			else
			{
				owner.do_offense_crossover();
			}
		}
		else
		{
			owner.do_offense_crossover();
		}
	}
}
